package com.topnav.mc.admin.entity.wrapper;

import com.topnav.mc.admin.entity.param.DeviceLogParam;
import com.topnav.mc.base.mc.McWrapper;
import org.springframework.util.StringUtils;

public class DeviceLogWrapper extends McWrapper<DeviceLogParam> {

    public DeviceLogWrapper(DeviceLogParam entity) {
        super(entity);
        if (this.permissionGrade != null ){
            if (this.permissionGrade.getPermissionLevel() == 1){
                this.eq("d.user_id",this.permissionGrade.getUserId());
            }else if (this.permissionGrade.getPermissionLevel() == 2){
                this.eq("d.org_id",this.permissionGrade.getOrgId());
            }else if (this.permissionGrade.getPermissionLevel() == 3 || this.permissionGrade.getPermissionLevel() == 4){
                this.likeRight("o.path",this.permissionGrade.getOrgPath());
            }
        }

        if (entity != null){
            if (entity.getId()!=null){this.eq("l.id",entity.getId());}

            if (entity.getFromTime()!=null){
                this.ge("l.create_time",entity.getFromTime());
            }
            if (entity.getToTime()!=null){
                this.le("l.create_time",entity.getToTime());
            }

            if (!StringUtils.isEmpty(entity.getDeviceCode())){
                this.like("d.code",entity.getDeviceCode());
            }

            if (entity.getDeviceId() != null){
                this.eq("l.device_id",entity.getDeviceId());
            }
            if (entity.getOrgId() != null){
                this.eq("d.org_id",entity.getOrgId());
            }
            if (entity.getUserId() != null){
                this.eq("d.user_id",entity.getUserId());
            }
            if (entity.getAction() != null){
                this.eq("l.action",entity.getAction());
            }


            this.orderByDesc("l.id");

        }
    }
}
